#!/usr/bin/python3
# coding=utf-8
#
# Copyright (C) 2023-2025. Huawei Technologies Co., Ltd. All rights reserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# ===============================================================================

import sys
import numpy as np

data_type = np.uint8

def verify_result(output, golden):
    output = np.fromfile(output, dtype=data_type).reshape(-1)
    golden = np.fromfile(golden, dtype=np.uint8).reshape(-1)

   # 比较是否一致
    different_indexes = np.where(output != golden)[0]

    # 打印前 10 个不一致的元素
    for i, idx in enumerate(different_indexes):
        print(f"data index: {idx:06d}, expected: {golden[idx]}, actual: {output[idx]}")
        if i >= 9:
            break

    error_ratio = float(len(different_indexes)) / golden.size
    print(f"error ratio: {error_ratio:.4f}")

    return error_ratio == 0.0  # 输出必须完全一致


if __name__ == '__main__':
    try:
        res = verify_result(sys.argv[1], sys.argv[2])
        if not res:
            raise ValueError("[ERROR] result error")
        else:
            print("test pass")
    except Exception as e:
        print(e)
        sys.exit(1)
